package class51To60;

import java.io.*;
import java.util.Arrays;

public class LeftRightLess {

    public static int MAX_N = 1000005;

    public static int[] arr = new int[MAX_N];

    public static int n;

    public static int[][] ret = new int[MAX_N][2];

    public static int[] ans = new int[MAX_N];

    public static int[] stack = new int[MAX_N];

    public static int size;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        while (in.nextToken() != StreamTokenizer.TT_EOF) {
            n = (int) in.nval;
            for (int i = 0; i < n; i++) {
                in.nextToken();
                arr[i] = (int) in.nval;
            }
            leftRightLarge();
            for (int i = 0; i < n; i++) {
                out.print((ans[i] + 1) + " ");
            }
        }
        clear();
        out.flush();
        out.close();
        br.close();
    }

    private static void leftRightLarge() {
        size = 0;
        for (int i = 0; i < n; i++) {
            int x = arr[i];
            while (size > 0 && arr[stack[size - 1]] <= x) {
                int cur = stack[--size];
                ans[cur] = i;
            }
            stack[size++] = i;
        }
        while (size > 0) {
            int cur = stack[--size];
            ans[cur] = -1;
        }
        for (int i = n - 2; i >= 0; i--) {
            if (ans[i] != -1 && arr[i] == arr[ans[i]]) {
                ans[i] = ans[ans[i]];
            }
        }
    }

    private static void leftRightLess() {
        size = 0;
        for (int i = 0; i < n; i++) {
            int x = arr[i];
            while (size > 0 && arr[stack[size - 1]] >= x) {
                int cur = stack[--size];
                ret[cur][0] = size > 0 ? stack[size - 1] : -1;
                ret[cur][1] = i;
            }
            stack[size++] = i;
        }
        while (size > 0) {
            int cur = stack[--size];
            ret[cur][0] = size > 0 ? stack[size - 1] : -1;
            ret[cur][1] = -1;
        }
        for (int i = n - 2; i >= 0; i--) {
            if (ret[i][1] != -1 && arr[i] == arr[ret[i][1]]) {
                ret[i][1] = ret[ret[i][1]][1];
            }
        }
    }

    public static void clear() {
        Arrays.fill(arr, 0);
        for (int i = 0; i <= n; i++) {
            Arrays.fill(ret[i], 0);
        }
    }
}
